package com.xiaoyu.lanling.feature.moment.fragment.detail

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.feature.moment.controller.detail.LikeDetailListController
import com.xiaoyu.lanling.feature.moment.data.detail.LikeDetailListData
import com.xiaoyu.lanling.view.OnShowFragment
import kotlinx.android.synthetic.main.fragment_like_list.*

class LikeListFragment : OnShowFragment() {

    private lateinit var listController: LikeDetailListController

    companion object {

        val KEY_FEED_ID = "key_feed_id"

        fun newInstance(feedId: String): LikeListFragment {
            val args = Bundle()
            args.putString(KEY_FEED_ID, feedId)
            val fragment = LikeListFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_like_list, container, false)
    }

    override fun onViewCreatedSafelyAfterAppFinishInit(view: View, savedInstanceState: Bundle?) {
        initData()
    }

    private fun initData() {
        activity?.let {
            val feedId = arguments?.getString(KEY_FEED_ID)?:return
            listController = LikeDetailListController.create(it, LikeDetailListData(feedId), swipe_refresh_layout, recyclerview)
            listController.loadFirstPageData()
        }
    }
}